﻿<Page x:Class="CAION2.Views.SelectItemPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:controls="clr-namespace:CAION2.Controls"
      xmlns:helpers="clr-namespace:CAION2.Helpers"
      xmlns:resources="clr-namespace:CAION2.Properties"
      xmlns:viewModels="clr-namespace:CAION2.ViewModels">

    <Page.DataContext>
        <viewModels:SelectItemDialogViewModel />
    </Page.DataContext>

    <Page.Resources>

        <viewModels:ItemTypeColorConverter x:Key="ItemTypeColor" />

        <Style x:Key="ItemsListViewItem"
               BasedOn="{StaticResource {x:Type ListViewItem}}"
               TargetType="ListViewItem">
            <Setter Property="Foreground" Value="{DynamicResource ItemText}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <Grid>
                            <Border Name="Selection" Visibility="Collapsed" />

                            <GridViewRowPresenter HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                                  Content="{TemplateBinding ContentControl.Content}"
                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Selection" Property="Visibility" Value="Visible" />
                                <Setter TargetName="Selection" Property="Background" Value="{DynamicResource ItemBackgroundHover}" />
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextHover}" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Selection" Property="Visibility" Value="Visible" />
                                <Setter TargetName="Selection" Property="Background" Value="{DynamicResource ItemBackgroundSelected}" />
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextDisabled}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="true">
                    <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Page.Resources>

    <Grid Style="{StaticResource ContentRoot}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="440" />
            <ColumnDefinition Width="440" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <WrapPanel HorizontalAlignment="Left" Orientation="Horizontal">
            <CheckBox Margin="8,0,2,6"
                      Command="{Binding LoadItemsCommand}"
                      Content="{x:Static resources:Resources.Items_Common}"
                      IsChecked="{Binding QualityFilter[0],
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Margin="8,0,2,6"
                      Background="#FF48C23F"
                      Command="{Binding LoadItemsCommand}"
                      Content="{x:Static resources:Resources.Items_Rare}"
                      IsChecked="{Binding QualityFilter[1],
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Margin="8,0,2,6"
                      Background="#FF00ADEF"
                      Command="{Binding LoadItemsCommand}"
                      Content="{x:Static resources:Resources.Items_Legend}"
                      IsChecked="{Binding QualityFilter[2],
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Margin="8,0,2,6"
                      Background="#FFFFCC00"
                      Command="{Binding LoadItemsCommand}"
                      Content="{x:Static resources:Resources.Items_Unique}"
                      IsChecked="{Binding QualityFilter[3],
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Margin="8,0,2,6"
                      Background="#FFF79646"
                      Command="{Binding LoadItemsCommand}"
                      Content="{x:Static resources:Resources.Items_Epic}"
                      IsChecked="{Binding QualityFilter[4],
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Margin="8,0,2,6"
                      Background="#FF7316E8"
                      Command="{Binding LoadItemsCommand}"
                      Content="{x:Static resources:Resources.Items_Mythic}"
                      IsChecked="{Binding QualityFilter[5],
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
        </WrapPanel>

        <controls:SearchTextBox Grid.Row="1"
                                Margin="0,5,160,10"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Top"
                                BorderThickness="{Binding FilterErrorBorder}"
                                Text="{Binding FilterText,
                                               Mode=TwoWay,
                                               UpdateSourceTrigger=PropertyChanged}"
                                ToolTip="{x:Static resources:Resources.RR_Filter}" />

        <ComboBox Grid.Row="1"
                  Margin="5,5,20,10"
                  HorizontalAlignment="Right"
                  ItemsSource="{Binding ItemParameters}"
                  SelectedIndex="0"
                  SelectedItem="{Binding SelectedParameter}" />

        <ListView Grid.Row="2"
                  IsSynchronizedWithCurrentItem="True"
                  ItemContainerStyle="{StaticResource ItemsListViewItem}"
                  ItemsSource="{Binding Items}"
                  SelectedItem="{Binding SelectedItem,
                                         Mode=TwoWay,
                                         UpdateSourceTrigger=PropertyChanged}"
                  SelectionMode="Single"
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  helpers:GridViewSort.AutoSort="True">
            <ListView.View>
                <GridView>
                    <GridView.Columns>
                        <GridViewColumn Width="50"
                                        Header="{x:Static resources:Resources.Status_LevelColumn}"
                                        helpers:GridViewSort.PropertyName="level">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Border BorderBrush="{Binding Path=quality, Converter={StaticResource ItemTypeColor}}"
                                            BorderThickness="2,0">
                                        <TextBlock Text="{Binding Path=level}"
                                                   TextAlignment="Center" />
                                    </Border>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                        <GridViewColumn Width="270"
                                        Header="{x:Static resources:Resources.RR_ListViewHeaderName}"
                                        helpers:GridViewSort.PropertyName="translate">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="4,4,0,4"
                                               Text="{Binding Path=translate}"
                                               TextWrapping="WrapWithOverflow" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                        <GridViewColumn Width="100"
                                        Header="{x:Static resources:Resources.Status_Value}"
                                        helpers:GridViewSort.PropertyName="parameter">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="4,4,0,4"
                                               Text="{Binding Path=parameter}"
                                               TextAlignment="Center"
                                               TextWrapping="WrapWithOverflow" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>

        <controls:ItemCard Grid.RowSpan="3"
                           Grid.Column="1"
                           Margin="10,0,0,0"
                           BorderBrush="{DynamicResource ModernButtonBorderDisabled}"
                           BorderThickness="1"
                           DataContext="{Binding Card}" />

    </Grid>
</Page>
